<?php namespace Admin\Controller;

use Hdphp\Controller\Controller;
use Admin\Model\Node;

class NodeController extends Controller
{
    protected $db;

    //构造函数
    public function __init()
    {
        $this->db = new Node;
    }

    //动作
    public function index()
    {
        $data = $this->db->getAll();
        View::with('data', $data);
        View::make();
    }

    //创建节点
    public function create()
    {
        if (IS_POST)
        {
            if ($this->db->store())
            {
                $this->success('添加成功','index');
            }
            else
            {
                $this->error($this->db->getError());
            }
        }
        else
        {

            View::with('node', $this->db->getAll());
            View::make();
        }
    }
}
